<template>
	<view class="wrap">
		<u-gap height="20" bg-color="#f5f5f5"></u-gap>


		<view class="list">
			<view class="list-call">
				<view class="" style="font-size: 22px;color:#5473e8;">IP:</view>
				<u-input class="u-input ip-text" type="text" v-model="baseUrl" maxlength="32"
					placeholder="ip和端口号(例如:10.10.101.61:8087)" value="admin" clear />
			</view>

			<!-- <view class="list-call">
				<view class="" style="font-size: 22px;color:#5473e8;">数据库:</view>
				<u-radio-group v-model="value" @change="radioGroupChange">
					<u-radio v-for="(item, index) in list" :key="index" :name="item.name" :disabled="item.disabled">
						{{item.name}}
					</u-radio>
				</u-radio-group>
			</view> -->
			<!-- <view class="list-call">
				<view class="" style="font-size: 22px;color:#5473e8;">特征码:</view>
				<input disabled="false" class="u-input" type="text" v-model="signature" maxlength="32" placeholder="请输入ip和端口号" value="admin"/>
			</view>
			<view class="list-call">
				<view class="" style="font-size: 22px;color:#5473e8;">注册码:</view>
				<input  class="u-input" type="text" v-model="registrationCode" maxlength="32" placeholder="请输入ip和端口号" value="admin"/>
			</view>
			<view class="list-call">
				<view class="" style="font-size: 22px;color:#5473e8;">注册信息:</view>
				<input  class="u-input" type="text" v-model="registrationInformation" maxlength="32" placeholder="请输入ip和端口号" value="admin"/>
			</view> -->


		</view>
		<view class="more-bottom-box">
			<!-- <view class="button"  @click="submitRegistrationCode()"><text>提交注册码</text></view> -->
			<view class="button" @click="submit()"><text>保存</text></view>
		</view>
		<!-- <u-row gutter="32" class="more-bottom-box" justify="center">
			<u-col span="10">
				<view><u-button class="more-button" type="primary" shape="circle" @click="scan1()">扫码</u-button>
				</view>
			</u-col>
			<u-col span="10">
				<view><u-button class="more-button" type="primary" shape="circle"
						@click="submit">上架</u-button>
				</view>
			</u-col>
		
		</u-row> -->
		<!-- <u-cell-group :border="false"> -->
		<!-- <u-cell-item title="通用" @click="navTo('/pages/sys/user/currency')" :arrow="true"></u-cell-item> -->
		<!-- <u-cell-item title="ip设置" @click="navTo('/pages/sys/setting/ip-setting')" :arrow="true"></u-cell-item>
			<u-cell-item title="注册码" @click="navTo('/pages/sys/setting/registration-code')" :arrow="true"></u-cell-item>
			<u-gap height="20" bg-color="#f5f5f5"></u-gap> -->
		<!-- <u-cell-item title="版本更新"  @click="navTo('')" :arrow="true"></u-cell-item> -->
		<!-- <u-cell-item title="隐私政策" @click="navTo('')" :arrow="true"></u-cell-item> -->
		<!-- <u-cell-item title="用户协议" @click="navTo('')" :arrow="true"></u-cell-item> -->
		<!-- </u-cell-group> -->
		<!-- <u-gap height="20" bg-color="#f5f5f5"></u-gap> -->
		<!-- <view>
			<u-button class="sign-out"  @click="logout" :hair-line="false">退出登录</u-button>
		</view> -->
	</view>
</template>
<script>
	/**
	 * Copyright (c) 2013-Now http://aidex.vip All rights reserved.
	 */
	export default {
		data() {
			return {
				list: [{
						name: 'oracle',
						disabled: false
					},
					{
						name: 'mysql',
						disabled: false
					},

				],
				// u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
				value: 'mysql',
				//baseUrl:'liucz.tpddns.cn:8087',
				baseUrl: '',
			};
		},
		onLoad() {
			const value = uni.getStorageSync('baseUrl')
			console.log('缓存' + value)
			if (value) {
				this.baseUrl = value
			} else {
				// this.baseUrl = 'zp450.gnway.cc:8000'
				if (process.env.NODE_ENV === 'development') {
					console.log('开发环境');
					this.baseUrl = '2444411sa6.qicp.vip'
				} else {
					console.log('生产环境');
					this.baseUrl = 'localhost:8087'
				}
				uni.setStorageSync('baseUrl', this.baseUrl);
				this.$u.toast('请修改并保存,');
			}

		},
		methods: {

			submit() {
				if (!this.baseUrl) {
					this.$u.toast('url不可以为空')
				}
				if (process.env.NODE_ENV === 'development') {
					if (this.baseUrl === 1 || this.baseUrl === '1') {
						this.baseUrl = 'zp450.gany.cc:8000'
					} else if (this.baseUrl === 2 || this.baseUrl === '2') {
						this.baseUrl = '2444411sa6.qicp.vip'
					} else if (this.baseUrl === 3 || this.baseUrl === '3') {
						this.baseUrl = 'lcz218.asuscomm.com:8087'
					}else if(this.baseUrl === 4 || this.baseUrl === '4'){
						this.baseUrl = 'pigx-gateway:9999'
					}else if(this.baseUrl === 5 || this.baseUrl === '5'){
						this.baseUrl = '47.102.210.209:9999'
					}
				}
				uni.setStorageSync('baseUrl', this.baseUrl);
				// uni.$u.vuex('vuex_config', baseUrl)

				// this.vuex_config.baseUrl = this.baseUrl;

				// vm.vuex_config.baseUrl
				this.$u.toast('ip已经设置为:' + uni.getStorageSync('baseUrl'));
				setTimeout(() => {
					uni.$emit("baseUrl", this.baseUrl)
					// this.$forceUpdate();
				}, 100);



				// uni.setStorageSync('logout', true);
				// setTimeout(() => {
				// 	uni.reLaunch({
				// 		url: '/pages/sys/login/index'
				// 	});
				// }, 500);

				// 	uni.reLaunch({
				// 	    url: '/pages/sys/login/index'
				// 	});
				// setTimeout(() => {
				// 	//刷新生效
				// 	// this.$router.go(0)

				// 	uni.navigateTo({
				// 		url: '/pages/sys/login/index'
				// 	});
				// }, 100);


			},
			submitRegistrationCode() {
				this.$u.toast('功能暂未启用')
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			openSettings() {
				// #ifdef APP-PLUS
				uni.getSystemInfo({
					success(res) {
						if (res.platform == 'ios') {
							plus.runtime.openURL("app-settings://");
						} else if (res.platform == 'android') {
							var main = plus.android.runtimeMainActivity();
							var Intent = plus.android.importClass("android.content.Intent");
							var mIntent = new Intent('android.settings.SOUND_SETTINGS');
							main.startActivity(mIntent);
						}
					}
				});
				// #endif
				// #ifndef APP-PLUS
				this.$u.toast('小程序端或H5端已是最新版，无需检查更新！');
				// #endif
			},
			logout() {
				this.$u.api.logout().then(res => {
					this.$u.toast(res.msg);
					// uni.$emit('logout',{msg:'退出登录'})
					uni.setStorageSync('logout', true);
					if (res.code == '200') {
						let self = this;
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/sys/login/index'
							});
						}, 500);
					}
				});
			}
		}
	};
</script>
<style lang="scss">
	@import 'index.scss';


	page {
		background-color: #f5f5f5;
	}

	/deep/ .u-cell-title {
		padding: 25rpx 30rpx;
		font-size: 30rpx;
	}

	.ip-text {
		font-size: 10rpx;
	}
</style>